<template>
    <div class="menu-container">
        <el-menu default-active="/HomePage" background-color="#001529" text-color="#fff" class="el-menu-vertical-demo"
            @open="handleOpen" @close="handleClose">
            <el-menu-item index="/HomePage" @click="handleMenuItemClick({ path: '/HomePage', title: '首页' })">
                <div style=" display: flex;">
                    <i class="iconfont">&#xe600;</i>
                    <span style="margin-left: 15px;">首页</span>
                </div>
            </el-menu-item>
            <MenuItem v-for="item in menuData" :key="item.id" :item="item" />
        </el-menu>
    </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import MenuItem from '../Menu/src/MenuItem.vue'
import { MenuDataApi } from '../../api/index'
import { useRouter } from 'vue-router'
import type { IMenu } from "../../types/index";
const router = useRouter();
const menuData = ref<IMenu[]>([]);

const handleOpen = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
const GetMenu = async (userTd: any) => {
    let res = await MenuDataApi(userTd);
    if (res.statusCode == 200) {
        menuData.value = res.data
    }
}

const handleMenuItemClick = (val: any) => {
    router.replace({
        path: val.path,
    });
}

onMounted(() => {
    GetMenu('04438b4d-539a-4ab9-aea4-7db25cf9a37e');
});

</script>
<style lang="scss" scoped>
.menu-container {
    height: 100%;
    background-color: #001529;
    border-right: 1px solid #eee;

    .el-menu {
        border-right: none;
    }
}
</style>
